﻿
Imports System.Data
Imports VSModel
Imports Cls_Common
Partial Class Control_QuanLyHoSo_HoSoChoXuLy
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim _IsUser As Integer = Session("IsUser")
            BindToGrid(_IsUser)
        End If
    End Sub

    Protected Sub BindToGrid(ByVal _LoaiNguoiDung As Integer)


        Using _data As New VSEntities
            ' mot cua
            Dim curHuyenId As Integer = Session("HuyenId")
            If _LoaiNguoiDung = LoaiNguoiDung.TCKH Then
                tckh.Visible = True
                'tiêp nhân tu mot cua - cấp mới
                Dim _pNew = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.ChoDuyet And q.CertifiedStatus = "M" Order By q.Created Descending Select q).ToList
                ltrSoluongChoNew.Text = _pNew.Count
                Dim pNew = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.ChoDuyet And q.CertifiedStatus = "M" Order By q.Created Descending Select q).Take(18).ToList
                With rptTiepNhanNew
                    .DataSource = pNew
                    .DataBind()
                End With
                'tiêp nhân tu mot cua - cấp đổi
                Dim _p2nd = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.ChoDuyet And q.CertifiedStatus = "D" Order By q.Created Descending Select q).ToList
                ltrSoluongChoNew.Text = _p2nd.Count
                Dim p2nd = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.ChoDuyet And q.CertifiedStatus = "D" Order By q.Created Descending Select q).Take(18).ToList
                With rptTiepNhan2nd
                    .DataSource = p2nd
                    .DataBind()
                End With
                'chuyển phong tài chính kế hoạch xử lý - cấp mới
                Dim CerNew = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.Daduyet And q.CertifiedStatus = "M" Order By q.Created Descending Select q).Take(18).ToList
                ltrSoluongDangXyLyNew.Text = CerNew.Count
                With rptChoXuLyNew
                    .DataSource = CerNew
                    .DataBind()
                End With
                'chuyển phong tài chính kế hoạch xử lý - cấp đổi
                Dim Cer2nd = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.Daduyet And q.CertifiedStatus = "D" Order By q.Created Descending Select q).Take(18).ToList
                ltrSoluongDangXyLy2nd.Text = Cer2nd.Count
                With rptChoXuLy2nd
                    .DataSource = Cer2nd
                    .DataBind()
                End With
                'phòng tài chính kế hoạch duyệt chờ ký hoàn tất
                Dim _l As List(Of uspCertifiedHouseholdSelectAll_Result) = _data.uspCertifiedHouseholdSelectAll("", "1900-01-01 00:00:00", "3999-12-31 00:00:00", "", "", -1, "", "" _
                                                                                                                , "1900-01-01 00:00:00", "3999-12-31 00:00:00", "", "", "", "", "", "", "", "" _
                                                                                                                , "", "", -1, curHuyenId, 1, 18).ToList
                If _l.Count > 0 Then
                    ltrHoanTat.Text = _l.FirstOrDefault.Total()
                End If
                Dim l = (From q In _l Where
                                        q.StatusId = TinhTrangHoSo.Hoantat Or
                                        q.StatusId = TinhTrangHoSo.ThueChoXuly Or
                                        q.StatusId = TinhTrangHoSo.ThueDangXuly Or
                                        q.StatusId = TinhTrangHoSo.ThueDuyet
                                        Select q).ToList

                With rptHoanTat
                    .DataSource = l
                    .DataBind()
                End With

                'hồ sơ bị trả về từ thuế
                Dim _j = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.ThueKhongDuyet Order By q.Created Descending Select q).ToList
                ltrTraVe.Text = _j.Count
                Dim j = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.ThueKhongDuyet Order By q.Created Descending Select q).Take(18).ToList
                With rptTraVe
                    .DataSource = j
                    .DataBind()
                End With
            End If
        End Using
    End Sub
    Protected Sub rptTiepNhanNew_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptTiepNhanNew.ItemDataBound, rptTiepNhan2nd.ItemDataBound, rptChoXuLyNew.ItemDataBound, rptChoXuLy2nd.ItemDataBound, rptHoanTat.ItemDataBound, rptTraVe.ItemDataBound
        Using _data As New VSEntities
            Dim row = CType(e.Item.DataItem, Object)
            Dim hplTitle As HyperLink = e.Item.FindControl("hplTitle")
            Dim _NgayTao As String
            Dim _id As Integer = row.CertifiedID
            Dim p = (From q In _data.CertifiedHouseholds Where q.CertifiedID = _id Select q).FirstOrDefault
            If Not p.Created Is Nothing Then
                _NgayTao = CType(p.Created, Date).ToString("dd/MM/yyyy")
            Else
                _NgayTao = ""
            End If
            hplTitle.Text = p.Ow_Name & " - " & "Ngày nhận: " & _NgayTao
            hplTitle.NavigateUrl = "../../Page/QuanLyHoSo/Detail.aspx?Certifiedid=" & p.CertifiedID
        End Using
    End Sub
End Class
